package com.eshop.modules.product.service.impl;

import java.lang.invoke.SerializedLambda;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import java.util.Date;
import com.alibaba.fastjson.JSON;
import java.util.Map;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.product.service.StoreProductAttrResultService;
import com.eshop.modules.product.domain.StoreProductAttrResult;
import com.eshop.modules.product.service.mapper.StoreProductAttrResultMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class StoreProductAttrResultServiceImpl extends BaseServiceImpl<StoreProductAttrResultMapper, StoreProductAttrResult> implements StoreProductAttrResultService
{
    public void insertYxStoreProductAttrResult(final Map<String, Object> map, final Long productId) {
        final StoreProductAttrResult storeProductAttrResult = new StoreProductAttrResult();
        storeProductAttrResult.setProductId(productId);
        storeProductAttrResult.setResult(JSON.toJSONString(map));
        storeProductAttrResult.setChangeTime(new Date());
        final int count = this.count(Wrappers.<StoreProductAttrResult>lambdaQuery().eq(StoreProductAttrResult::getProductId, productId));
        if (count > 0) {
            this.remove(Wrappers.<StoreProductAttrResult>lambdaQuery().eq(StoreProductAttrResult::getProductId, productId));
        }
        this.save(storeProductAttrResult);
    }
}
